<?php


namespace App\Traits;

use Response;
use Symfony\Component\HttpFoundation\Response as FoundationResponse;

trait JsonResponse
{
    /**
     * @param string $message
     * @param int $code
     * @param array $data
     * @param int $httpCode
     * @param array $header
     * @return \Illuminate\Http\JsonResponse
     */
    public function success($message = 'success', $code = 200, $data = [], $httpCode = 200, $header = [])
    {
        $resData = compact('code', 'message', 'data');
        return Response::json($resData, $httpCode, $header, 256);
    }

    public function failed($message = 'fail', $code = 500, $data = [], $httpCode = 500, $header = [])
    {
        $resData = compact('code', 'message', 'data');
        return Response::json($resData, $httpCode, $header, 256);
    }

    /**
     * exception
     * @param \Exception $exception
     * @param int $code
     * @return \Illuminate\Http\JsonResponse
     */
    public function failException($message,\Exception $exception, $code = 500)
    {
        return $this->failed($message, $code, ['exception' => (array)$exception]);
    }


}